//
//  KLNavigationController.swift
//  新浪微博
//
//  Created by WTFKL on 17/8/4.
//  Copyright © 2017年 WTF. All rights reserved.
//

import UIKit

class KLNavigationController: UINavigationController {

    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBar.isHidden = true;

    }

    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count>0 {
            viewController.hidesBottomBarWhenPushed = true;
            
            if let vc = viewController as? KLBaseViewController  {
                var title = "返回";
//                vc.navItem.leftBarButtonItem?.setBackgroundImage(#imageLiteral(resourceName: "navigationButtonReturn"), for: .normal, barMetrics: .default);
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回";
                    vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, style: .plain, target: self, action: #selector(popBack), normalTextColor: #colorLiteral(red: 0.6000000238, green: 0.6000000238, blue: 0.6000000238, alpha: 1), highLightTextColor: #colorLiteral(red: 0.9372549057, green: 0.3490196168, blue: 0.1921568662, alpha: 1) ,isBack : true);
                    
                }
            }
            
        }
        
        super.pushViewController(viewController, animated: true);
    }
    
    func popBack(){
      popViewController(animated: true);
        
    }
}
